package com.itcast.donkey.adapters;

import android.content.Context;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;


import com.itcast.donkey.R;
import com.itcast.donkey.modles.TravelInItemModels;

import java.util.List;

/**
 * Created by lanouhn on 16/9/2.
 */
public class TravelInDayAdapter extends RecyclerView.Adapter<TravelInDayAdapter.INDayViewHolder> {
    private Context context;
    private TravelInItemModels.TripDaysBean travelInItemModels;
    private TravelInDayContentAdapter adapter;
    private List<TravelInItemModels.NotesLikesCommentsBean> notesLikesCommentsBeen;


    public TravelInDayAdapter(Context context, TravelInItemModels.TripDaysBean travelInItemModels, List<TravelInItemModels.NotesLikesCommentsBean> notesLikesCommentsBeen) {
        this.context = context;
        this.travelInItemModels = travelInItemModels;
        this.notesLikesCommentsBeen = notesLikesCommentsBeen;
    }

    @Override
    public INDayViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_travel_inday_item, null);
        INDayViewHolder holder = new INDayViewHolder(view);
        return holder;
    }

    @Override
    public int getItemViewType(int position) {
        return position;
    }

    @Override
    public void onBindViewHolder(INDayViewHolder holder, int position) {
        if (travelInItemModels.getNodes().get(position).getEntry_name() == null) {
            holder.relInDay.setVisibility(View.GONE);
        } else {
            holder.score.setVisibility(View.VISIBLE);

            holder.view.setVisibility(View.VISIBLE);
            holder.ivHead.setVisibility(View.VISIBLE);
            holder.relInDay.setVisibility(View.VISIBLE);
            holder.entryName.setText(travelInItemModels.getNodes().get(position).getEntry_name() + "");
            if (travelInItemModels.getNodes().get(position).getMemo().getPrice_amount() != null) {
                holder.priceAmount.setText("门票:" + travelInItemModels.getNodes().get(position).getMemo().getPrice_amount() + "元");
            }
            if (travelInItemModels.getNodes().get(position).getMemo().getTime() != null) {
                holder.time.setText("游览:" + travelInItemModels.getNodes().get(position).getMemo().getTime() + "分钟");
            }
        }
        RecyclerView recyclerView = new RecyclerView(context);
        adapter = new TravelInDayContentAdapter(context, travelInItemModels.getNodes().get(position), notesLikesCommentsBeen);
        recyclerView.setAdapter(adapter);

        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(context);
        recyclerView.setLayoutManager(linearLayoutManager);
        holder.linInDay.addView(recyclerView);


    }


    @Override
    public int getItemCount() {
        return travelInItemModels.getNodes().size();
    }


    public class INDayViewHolder extends RecyclerView.ViewHolder {
        private RelativeLayout relInDay;
        private ImageView ivHead;
        private TextView entryName;
        private ImageView score;
        private TextView priceAmount;
        private View view;
        private TextView time;
        private LinearLayout linInDay;

        public INDayViewHolder(View itemView) {
            super(itemView);
            relInDay = (RelativeLayout) itemView.findViewById(R.id.rel_inDay);
            ivHead = (ImageView) itemView.findViewById(R.id.iv_head);
            entryName = (TextView) itemView.findViewById(R.id.entry_name);
            score = (ImageView) itemView.findViewById(R.id.score);
            priceAmount = (TextView) itemView.findViewById(R.id.price_amount);
            view = (View) itemView.findViewById(R.id.view);
            time = (TextView) itemView.findViewById(R.id.time);
            linInDay = (LinearLayout) itemView.findViewById(R.id.lin_inDay);
        }
    }
}
